/**
 * 导出日志列表
 * 
 * /admin/exportlog
 */

const Log = require('../../../models/log')
const utils = require('../../../utils/index')
const $ = require('../../../utils/common')

const export_log = function(req,res) {
    try{
        Log.findAndCountAll({
            // 排序
            order: [
                ['createdAt', 'DESC'],
            ],
            // 返回的属性
            attributes: ['user_name', 'user_ip', 'request_module', 'request_behavior', 'request_status', 'createdAt', 'request_method', 'request_parameter'],
        }).then(result => {
            res.json({
                code: 200,
                message: 'success',
                data: result.rows,
                total: result.count
            })
            // 生成一条操作日志
            utils.create_a_log(req, '日志', '导出')
        })
        return
    }

    catch(error) {
        $.sendMessage(res, 0000, 'error' + error)
    }
}

module.exports = export_log